<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE">
	<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
	<title>个人注册</title>

    <link rel="stylesheet" type="text/css" href="/static/home/css/all.css" />
    <link rel="stylesheet" type="text/css" href="/static/home/css/pages-register.css" />
    
	<script type="text/javascript" src="/static/home/js/all.js"></script>
	<script type="text/javascript" src="/static/home/js/pages/register.js"></script>
</head>

<body>
	<div class="register py-container ">
		<!--head-->
		<div class="logoArea">
			<a href="" class="logo"></a>
		</div>
		<!--register-->
		<div class="registerArea">
			<h3>注册新用户<span class="go">我有账号，去<a href="logins.html" target="_blank">登陆</a></span></h3>
			<div class="info">
				<form action="register" method="post" id="reg_form" class="sui-form form-horizontal">
					<div class="control-group">
						<label class="control-label">手机号：</label>
						<div class="controls">
							<input type="text" id="phone" name="phone" placeholder="请输入你的手机号" class="input-xfat input-xlarge">
							<span class="error"></span>
						</div>
					</div>
					<div class="control-group">
						<label for="inputPassword" class="control-label">验证码：</label>
						<div class="controls">
							<input type="text" id="code" name="code" placeholder="验证码" class="input-xfat input-xlarge" style="width:120px">
							<button type="button" class="btn-xlarge" id="dyMobileButton">发送验证码</button>
							<span class="error"></span>
						</div>
					</div>
					<div class="control-group">
						<label for="inputPassword" class="control-label">登录密码：</label>
						<div class="controls">
							<input type="password" id="password" name="password" placeholder="设置登录密码" class="input-xfat input-xlarge">
							<span class="error"></span>
						</div>
					</div>
					<div class="control-group">
						<label for="inputPassword" class="control-label">确认密码：</label>
						<div class="controls">
							<input type="password" id="repassword" name="repassword" placeholder="再次确认密码" class="input-xfat input-xlarge">
							<span class="error"></span>
						</div>
					</div>
					<div class="control-group">
						<label for="inputPassword" class="control-label">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>
						<div class="controls">
							<input name="m1" type="checkbox" value="2" checked=""><span>同意协议并注册《品优购用户协议》</span>
							<span class="error"></span>
						</div>
					</div>
					<div class="control-group">
						<label class="control-label"></label>
						<div class="controls btn-reg">
							<a id="reg_btn" class="sui-btn btn-block btn-xlarge btn-danger reg-btn" href="javascript:;">完成注册</a>
						</div>
					</div>
				</form>
				<div class="clearfix"></div>
			</div>
		</div>
		<!--foot-->
		<div class="py-container copyright">
			<ul>
				<li>关于我们</li>
				<li>联系我们</li>
				<li>联系客服</li>
				<li>商家入驻</li>
				<li>营销中心</li>
				<li>手机品优购</li>
				<li>销售联盟</li>
				<li>品优购社区</li>
			</ul>
			<div class="address">地址：北京市昌平区建材城西路金燕龙办公楼一层 邮编：100096 电话：400-618-4000 传真：010-82935100</div>
			<div class="beian">京ICP备08001421号京公网安备110108007702
			</div>
		</div>
	</div>
</body>

<script>
	// 验证手机号
	$('#dyMobileButton').click(function () {
		var mobile = $('#phone').val();
		var preg = /^1[3589]\d{9}$/;
		if (mobile == '' || !preg.test(mobile)){
			$('.error:eq(0)').html("手机格式不正确");
			return false;//禁止执行下面的代码
		} else {
			$('.error:eq(0)').empty();
		}
		// 倒计时
		var that = $(this);
		that.attr('disabled',true);//点击过后不能再次点击
		// 60s之后才能再次发送
		var second = 60;
		var timer = setInterval(function () {
			second--// 先减一
			if (second > 0) {
				that.text(second + 's后再次发送')
			} else  {
				that.text('发送验证码')
				that.attr('disabled',false);//打开点击功能
				clearInterval(timer);// 清空定时器
			}
		},1000);

		// 发送验证码
		$.ajax({
			url:'sendCode',
			dataType:'json',
			data:{mobile:mobile},
			type:"POST",
			success:function (result) {
				alert(result.msg);
				return ;
			}
		})
	});
	/**
	 * 提交
	 */
	$('#reg_btn').click(function () {
		// 验证信息
		var mobile = $('#phone').val();
		var preg = /^1[3589]\d{9}$/;
		if (mobile == '' || !preg.test(mobile)){
			$('#phone').next().html("手机格式不正确");
			return false;//禁止执行下面的代码
		} else {
			$('#phone').next().empty();
		}
		// 验证密码
		var password = $('#password').val();
		if (password == '' || password.length < 6){
			$('#password').next().html("密码至少是6位");
			return false;//禁止执行下面的代码
		} else {
			$('#password').next().empty();
		}
		// 验证手机号
		var repassword = $('#repassword').val();
		if (repassword == '' || repassword.length < 6){
			$('#repassword').next().html("确认密码至少是6位");
			return false;//禁止执行下面的代码
		} else if (repassword != password) {
			$('#repassword').next().html("密码不一致");
			return false;//禁止执行下面的代码
		}else {
			$('#repassword').next().empty();
		}
		// 验证验证码
		var code = $('#code').val();
		if (code == '' || code.length != 4){
			$('#code').next().html("验证码至少是四位");
			return false;//禁止执行下面的代码
		} else {
			$('#code').next().empty();
		}
		// 验证是否同意协议
		if (!$("[name='m1']").prop('checked')) {
			$("[name='m1']").next().next().html("必须同意协议");
			return false;//禁止执行下面的代码
		}
		$('form').submit();
	})
</script>

</html>